package CR2;

import java.io.File;
import java.util.ArrayList;
import java.util.ListIterator;

import tools.FileTools;

/**
 * @author Kevin implement DOS robocopy /MOVE /S X:\Kevin\Pictures\[NEW]
 *         X:\Kevin\Pictures\[RAW]\WORKING *.CR2
 * 
 * @param args
 */
public class CR2Mover {

	final static String srcFolderBaseFP = "X:\\Kevin\\Pictures\\[NEW]";
	final static String dstFolderBaseFP = "X:\\Kevin\\Pictures\\[RAW]\\Working";

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		FileTools fileTools = new FileTools();
		File srcBaseFolder = new File(srcFolderBaseFP);

		ArrayList<String> listSub = fileTools.listSubFolderOnly(srcBaseFolder.getPath());

		ListIterator<String> litr = listSub.listIterator();

		System.out.println(listSub.size());

		while (litr.hasNext()) {
			String folder = litr.next();
			File srcChildFolder = new File(srcFolderBaseFP, folder);
			File destChildFolder = new File(dstFolderBaseFP, folder);

			System.out.println(srcChildFolder.getPath());
			System.out.println(destChildFolder.getPath());

			if (!destChildFolder.exists()) {
				destChildFolder.mkdir();
			}

			File[] files = srcChildFolder.listFiles(fileTools.fileFilterExt("CR2"));

			for (File file : files) {
				File newFile = new File(destChildFolder.getPath(), file.getName());
				if (file.renameTo(newFile)) {
					System.out.print("moved CR2 file: ");
					System.out.println(file.getPath());
				} else {
					System.out.print("Failed to move CR2 file: ");
					System.out.println(file.getPath());
				}

				// FileTools.moveFile(file.getPath(),
				// destChildFolder.getPath());
			}

		}
	}
}
